﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using Astro.Core;

namespace Astro.Plus
{
    [Chalk("picasa")]
    public class Picasa
    {
        public static Picasa Instance
        {
            get
            {
                return new Picasa();
            }
        }

        # region Utilities
        const string imageName = "astrotelligent";
        public string GetThumbnail(string url, string size)
        {
            return GetThumbnail(url, size, false);
        }

        public string GetThumbnail(string url, string size, bool crop)
        {
            if (string.IsNullOrEmpty(url))
                return "";

            string inCrop = "";
            if (crop)
            {
                inCrop = "-c";
            }

            string[] pathSlip = url.Split('/');
            string sizeDefine = pathSlip[pathSlip.Length - 2];
            string fileName = pathSlip[pathSlip.Length - 1];

            if (sizeDefine.StartsWith("s"))
            {
                return url.Replace(fileName, String.Format("{0}/{1}", size.ToString() + inCrop, fileName));
            }
            else
            {
                return url.Replace(sizeDefine, size.ToString() + inCrop);                
            }
        }
        # endregion
    }
}